using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CreateHttpCookiePage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(Request.Cookies["Remember"]!=null)
        {
            HttpCookie httpCookie=
            Request.Cookies["EmailAndTime"];
            txtEmail.Text=httpCookie.Values["Email"].ToString();   
                
        }
    }
  
    
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        WriteCookie();
        //WriteCookie(DateTime.Now);
        //WriteCookie(DateTime.Now,"RecruitVietnam.com");
        Session["jsemail"] = txtEmail.Text;
        Session.Contents.Add("jsid", "100");
        Response.Redirect("ReadCookiePage.aspx");
    }
    void WriteCookie()
    {
        if(CheckBoxRememberEmail.Checked)
        {
            HttpCookie httpCookie = new HttpCookie("Remember", "Yes");
            Response.Cookies.Add(httpCookie);
            httpCookie = new HttpCookie("EmailAndTime");
            httpCookie.Values.Add("Email", txtEmail.Text);
            httpCookie.Values.Add("Time", DateTime.Now.ToShortDateString());
            Response.Cookies.Add(httpCookie);
        }
     }
    void WriteCookie(DateTime dateTime)
    {
        if (CheckBoxRememberEmail.Checked)
        {
            HttpCookie httpCookie = new HttpCookie("Remember", "Yes");
            Response.Cookies.Add(httpCookie);
            httpCookie = new HttpCookie("EmailAndTime");
            httpCookie.Values.Add("Email", txtEmail.Text);
            httpCookie.Values.Add("Time", DateTime.Now.ToShortDateString());
            TimeSpan timeSpan = new TimeSpan(100, 0, 0, 0);
            httpCookie.Expires = dateTime;
            httpCookie.Expires = dateTime.Add(timeSpan);
            Response.Cookies.Add(httpCookie);
        }
        
    }
    void WriteCookie(DateTime dateTime, string domainName)
    {
        if (CheckBoxRememberEmail.Checked)
        {
            HttpCookie httpCookie = new HttpCookie("Remember", "Yes");
            Response.Cookies.Add(httpCookie);
            httpCookie = new HttpCookie("EmailAndTime");
            httpCookie.Values.Add("Email", txtEmail.Text);
            httpCookie.Values.Add("Time", DateTime.Now.ToShortDateString());
            TimeSpan timeSpan = new TimeSpan(100, 0, 1, 0);
            httpCookie.Expires = dateTime;
            httpCookie.Expires = dateTime.Add(timeSpan);
            httpCookie.Domain=domainName;            
            Response.Cookies.Add(httpCookie);
        }

    }
}
